<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>Examples</title>
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <link href="" rel="stylesheet" />
</head>

<body>
    <div id="app">
        <input v-model = "val" type="text">
        <button @click = "addItem">添加</button>
        <div>
            <h2>
                正在进行  ---  {{ len }}
            </h2>
            <ul>
                <li v-for="(item, index) in arr" v-show = "!item.checked">
                    <input v-model = "item.checked" type="checkbox">
                    {{ item.val }}     
                    <button @click="remove(index)">删除</button>
                </li>
            </ul>

            <h2>
                已经完成  ---  {{ arr.length - len }}
            </h2>
            <ul>
                <li v-for="(item, index) in arr" v-show = "item.checked">
                    <input v-model = "item.checked" type="checkbox">
                    {{ item.val }}     
                    <button @click="remove(index)">删除</button>
                </li>
            </ul>
        </div>
    </div>
    <script src="./js/vue.js"></script>
    <script>
        new Vue({
            el: "#app",
            data: {
                // input中输入的值
                val: "",
                // 总的任务
                arr: []
            },
            created() {
                // forEach  没有返回值
                // map   有返回值
                // filter   做筛选
                // var datas = this.arr.filter((item) => {
                //     return item === 2
                // })
                // // [2]
                // console.log(datas)
            },
            computed: {
                len() {
                    return this.arr.filter((item) => {
                        return item.checked === false
                    }).length
                }
            },
            methods: {
                addItem() {
                    this.arr.push({
                        val: this.val,
                        checked: false
                    })
                    this.val = ""
                },
                remove(index) {
                    this.arr.splice(index, 1)
                }
            }
        })
    </script>
</body>

</html>